package org.desktop.web.client.role.form.validator;

import java.util.ArrayList;
import java.util.List;

import org.desktop.web.client.role.RoleService;
import org.desktop.web.client.role.RoleServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.Editor;
import com.google.gwt.editor.client.EditorError;
import com.sencha.gxt.widget.core.client.form.TextField;
import com.sencha.gxt.widget.core.client.form.Validator;
import com.sencha.gxt.widget.core.client.form.error.DefaultEditorError;
import com.sencha.gxt.widget.core.client.info.Info;

public class CodRoleValidator implements Validator<String> {

	public static final String NOT_VALID_VALUE = "UNIQUE_COD_ROLE_VIOLATED";
	private RoleServiceAsync roleService = GWT.create(RoleService.class);

	@Override
	public List<EditorError> validate(Editor<String> editor, String value) {
		TextField txt = ((TextField) editor);
		List<EditorError> errors = new ArrayList<EditorError>();
		if (value != null && value.equals(NOT_VALID_VALUE)) {
			errors.add(new DefaultEditorError(editor,
					"Codice gia' presente in archivio", value));

		}
		if (errors.size() == 0) {
		} else {
			txt.showErrors(errors);
		}
		return errors;
	}

}
